package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/category")
//分类相关接口
public class CategoryController {
    private final CategoryService categoryService;

    //分类分页查询
    @GetMapping("/page")
    public Result<PageResult> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("分类分页查询:{}", categoryPageQueryDTO);
        return Result.success(categoryService.pageQuery(categoryPageQueryDTO));
    }

    //更新分类信息
    @PutMapping
    public Result editCategory(@RequestBody CategoryDTO categoryDTO) {
        log.info("更新分类信息：:{}", categoryDTO);
        categoryService.updateCategory(categoryDTO);
        return Result.success();
    }

    //根据类型查询分类
    @GetMapping("/list")
    public Result<List<Category>> getCategoryByType(String type) {
        log.info("根据类型查询分类：{}",type);
        return Result.success(categoryService.getCategoryByType(type));
    }

    //新增分类
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO categoryDTO) {
        log.info("新增分类:{}", categoryDTO);
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }

    //启用、禁用分类
    @PostMapping("/status/{status}")
    public Result updateStatus(@PathVariable Integer status,Long id) {
        log.info("启用、禁用分类:{}",status,id);
        categoryService.updateStatus(status,id);
        return Result.success();
    }

    //根据id删除分类
    @DeleteMapping
    public Result deleteCategory(Long id) {
        log.info("根据id删除分类：{}",id);
        categoryService.deleteCategory(id);
        return Result.success();
    }
}
